/**
 * @file Singleton.h
 * @author haiming
 * @brief 懒汉模式实现的单例模式
 * 特点：单线程下，内存安全；调用GetInstance函数才会创建实例
 * 缺陷：为保证线程安全，需要加锁解锁
 * @version 0.2
 * @date 2024-04-24
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#pragma once
#include <stdio.h>

class Singleton
{
public:
    static Singleton* GetInstance();


private:
    Singleton(void);
    Singleton(const Singleton&){}
    Singleton operator=(const Singleton&){}
    ~Singleton(void);
    
    class _Inner{
    public:
        _Inner(){printf("create singleton inner.\n");};
        ~_Inner(){
            if(NULL != m_instance){
                delete m_instance;
                m_instance = NULL;
            }
        }
    };

    static Singleton* m_instance;
    static _Inner m_innert;
};


